package sort;

import sun.security.util.Length;

import java.util.Comparator;

/**
 * @Auther: wangliuyang
 * @Date: 2021/4/23 18:28
 * @Description: 冒泡排序
 */
public class BubbleSort {
    public static void bubbleSort(int[] nums) {
         for (int i = 0; i < nums.length - 1; i++) {
             for (int j = 0 ; j < nums.length - i - 1; j++) {
                 if (nums[j] > nums[j + 1]) {       //升序
                     //nums[j] < nums[j + 1]        //降序
                     swap(nums, j , j + 1);
                 }
             }
         }
    }

    private static void swap(int[] nums, int i, int j) {
        int tmp = nums[i];
        nums[i] = nums[j];
        nums[j] = tmp;
    }

    public static void main(String[] args) {
        int[] array = new int[]{2,5,6,7,3,7,1};
        bubbleSort(array); ;
        for (int i : array) {
            System.out.println(i);
        }
    }
}
